﻿@{
    ViewBag.Title = "重置密码";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@Styles.Render("~/Content/css/disablePage")
@*<header class="LogIn">
    <div class="LogInHead">
        <a onclick="turnBack()"><img src="~/images/TurnBack.png"><span>重置密码</span></a>
    </div>
</header>*@
<nav class="disable_mod_nav">
    <div class="lay_left">
        <a class="nav_back" onclick="turnBack()"><img src="/images/TurnBack.png"></a>
        <span>重置密码</span>
    </div>
</nav>
<section class="LogInCon">
    <div class="alert alert-warning" style="display:none" role="alert">
        <strong></strong>
    </div>

    <div class="LogInName">
        <span>用户名</span>
        <input type="tel" id="userName" placeholder="请输入手机号码作为用户名">
    </div>
    <div class="LogInName LogInYZM">
        <span>验证码</span>
        <input type="tel" id="securityCode" placeholder="请输入短信验证码">
        <input type="button" id="SecurityCodeWait" onclick="getSecurityCodeVal(this);" value=" 获取验证码">
    </div>
    <div class="LogInName LogInWord">
        <span>新密码</span>
        <input type="password" id="passWord" placeholder="至少6位">
        <a class="KeJian">
            <img id="PassWordInVisibale" src="~/images/KeJianFocus.png" style="display:block;">
            <img id="PassWordVisibale" src="~/images/KeJian.png" style="display:none;">
        </a>
    </div>

    <a class="LogInCheckbox" value="1">已阅读并同意<span onclick="goServiceProtocol()">便利超人使用条款</span></a>

    <input type="button" value="提交" class="LogInBtn" onclick="registerVal();" style="margin-top:10px;">
</section>

<script>

    //没有手机号时，获取验证码显示灰色
    window.onload = function () {
        $("#SecurityCodeWait").attr("style", "color:#999999");
    }
    //当输入11位手机号时将获取验证码显示为红色
    $(document).ready(function () {
        $("#userName").bind('input propertychange', function () {
            var keyword = $("#userName").val();
            if (keyword.length == 11) {
                $("#SecurityCodeWait").attr("style", "color:#FF571F");
            }
        });
    });


    function goServiceProtocol() {
        window.location.href = '@Url.Content("~/")' + 'Other/ServiceProtocol?url=/User/ResetPassword';
    }

    function turnBack() {
        window.location.href = '@Url.Content("~/")' + 'User/Login';
    }
    //获取注册验证码
    function getSecurityCode(obj, userName) {
        $(".alert").attr("style", "display:none");
        var registerRequestJson = {
            'uid': userName,
            'type': 2   //重置密码
        };
        var command = "get_identifying_code";
        doAjax(registerRequestJson, command, function (msg) {
            if (msg) {
                if (msg.result == "0") {
                    //获取成功
                    $(".alert").attr("style", "display:none");
                } else if (msg.result == "1") {
                    $("#userName").focus();
                    $(".alert").attr("style", "display:block");
                    $(".alert strong").html("服务器忙，请稍后重试！");
                    obj.removeAttribute("disabled");
                    obj.value = "获取验证码";
                    SecurityCodeWait = 60;
                } else {
                    $("#userName").focus();
                    $(".alert").attr("style", "display:block");
                    $(".alert strong").html("获取验证码失败！");
                    obj.removeAttribute("disabled");
                    obj.value = "获取验证码";
                    SecurityCodeWait = 0;
                }
            }
        });
    }
    //获取验证码验证
    function getSecurityCodeVal(obj) {
        $(".alert").attr("style", "display:none");
        var userName = $("#userName").val();
        if (!Val.isMobile(userName)) {
            $("#userName").focus();
            $(".alert").attr("style", "display:block");
            $(".alert strong").html("请输入正确的手机号！");
        } else {
            SCodeWait(obj);
            getSecurityCode(obj, userName);
        }
    }
    //验证码获取等待60s
    var SecurityCodeWait = 60;
    function SCodeWait(o) {
        if (SecurityCodeWait == 0) {
            o.removeAttribute("disabled");
            o.value = "获取验证码";
            SecurityCodeWait = 60;
        } else {
            o.setAttribute("disabled", true);
            o.value = "重新发送(" + SecurityCodeWait + ")";
            SecurityCodeWait--;
            setTimeout(function () {
                SCodeWait(o);
            },
			1000)
        }
    }
    //表单验证
    function registerVal() {
        $(".alert").attr("style", "display:none");
        var userName = $("#userName").val();
        var passWord = $("#passWord").val();
        var securityCode = $("#securityCode").val();
        if (!Val.isMobile(userName)) {
            $("#userName").focus();
            $(".alert").attr("style", "display:block");
            $(".alert strong").html("请输入正确的手机号！");
        } else if (!Val.IsPassWord(passWord)) {
            $("#passWord").focus();
            $(".alert").attr("style", "display:block");
            $(".alert strong").html("请输入至少6位字母加数字的密码！");
        } else if (securityCode < 99999) {
            $(".alert").attr("style", "display:block");
            $(".alert strong").html("请输入验证码！");
        } else {
            reSetPassword(userName, passWord, securityCode);
        }
    }
    //重置密码处理
    function reSetPassword(userName, passWord, securityCode) {
        $(".alert").attr("style", "display:none");
        var resetRequestJson = { 'uid': userName, 'pass_word': passWord, 'identifying_code': securityCode };
        var command = "reset_password";
        doAjax(resetRequestJson, command, function (msg) {
            if (msg.result == "0") {
                $(".alert").attr("style", "display:block");
                $(".alert strong").html("密码重置成功。");
                UserInfoMgr.logIn(userName, passWord, msg.unpicked_order_num, msg.score, msg.scale2cash);
                window.location.href = '@Url.Content("~/")' + 'User/Index';
            } else {
                $("#userName").focus();
                $(".alert").attr("style", "display:block");
                $(".alert strong").html("密码重置成败，请重试！");
            }
        });
    }
</script>
